using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using QuartzTypeLib;
namespace etbTOEIC
{
	/// <summary>
	/// Summary description for frmTopic.
	/// </summary>
	public class FormTopic : System.Windows.Forms.Form
	{
		public long SectionID = 0;
		public long TopicID = 0;

		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPage1;
		private System.Windows.Forms.Button buttonOk;
		private System.Windows.Forms.Button buttonCancel;
		private System.Windows.Forms.Button buttonHelp;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtTape;
		private System.Windows.Forms.TextBox txtSound;
		private System.Windows.Forms.Button btnSound;
		private System.Windows.Forms.Button btnPlay;
		private System.Windows.Forms.TextBox txtImage;
		private System.Windows.Forms.Button btnImage;
		private System.Windows.Forms.PictureBox pBoxImage;
		private System.Windows.Forms.TextBox txtNote;
		private System.Windows.Forms.GroupBox groupBoxNote;
		private System.Windows.Forms.GroupBox groupBoxImage;
		private System.Windows.Forms.GroupBox groupBoxSound;
		private System.Windows.Forms.GroupBox groupBoxClassify;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox txtDiffLevel;
		private System.Windows.Forms.ComboBox cmbBook;
		private System.Windows.Forms.TextBox txtPassages;
		private System.Windows.Forms.TextBox txtTitle;
		private System.Windows.Forms.TextBox txtSectionTitle;
		// media 
		private const int WM_APP = 0x8000;
		private const int WM_GRAPHNOTIFY = WM_APP + 1;
		private const int EC_COMPLETE = 0x01;
		private const int WS_CHILD = 0x40000000;
		private const int WS_CLIPCHILDREN = 0x2000000;

		private FilgraphManager m_objFilterGraph = null;
		private IBasicAudio m_objBasicAudio = null;
		private IVideoWindow m_objVideoWindow = null;
		private IMediaEvent m_objMediaEvent = null;
		private IMediaEventEx m_objMediaEventEx = null;
		private IMediaPosition m_objMediaPosition = null;
		private IMediaControl m_objMediaControl = null;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormTopic(long SID, long TID, string stSTitle)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			RichTextBox rtb = new RichTextBox();
			
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			SectionID = SID;
			TopicID = TID;
			txtSectionTitle.Text = stSTitle;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormTopic));
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.tabPage1 = new System.Windows.Forms.TabPage();
			this.groupBoxClassify = new System.Windows.Forms.GroupBox();
			this.txtDiffLevel = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.cmbBook = new System.Windows.Forms.ComboBox();
			this.label4 = new System.Windows.Forms.Label();
			this.groupBoxNote = new System.Windows.Forms.GroupBox();
			this.txtNote = new System.Windows.Forms.TextBox();
			this.groupBoxImage = new System.Windows.Forms.GroupBox();
			this.txtPassages = new System.Windows.Forms.TextBox();
			this.txtImage = new System.Windows.Forms.TextBox();
			this.btnImage = new System.Windows.Forms.Button();
			this.pBoxImage = new System.Windows.Forms.PictureBox();
			this.groupBoxSound = new System.Windows.Forms.GroupBox();
			this.txtSound = new System.Windows.Forms.TextBox();
			this.btnSound = new System.Windows.Forms.Button();
			this.btnPlay = new System.Windows.Forms.Button();
			this.txtTape = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.txtTitle = new System.Windows.Forms.TextBox();
			this.txtSectionTitle = new System.Windows.Forms.TextBox();
			this.buttonOk = new System.Windows.Forms.Button();
			this.buttonCancel = new System.Windows.Forms.Button();
			this.buttonHelp = new System.Windows.Forms.Button();
			this.tabControl1.SuspendLayout();
			this.tabPage1.SuspendLayout();
			this.groupBoxClassify.SuspendLayout();
			this.groupBoxNote.SuspendLayout();
			this.groupBoxImage.SuspendLayout();
			this.groupBoxSound.SuspendLayout();
			this.SuspendLayout();
			// 
			// tabControl1
			// 
			this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.tabControl1.Controls.Add(this.tabPage1);
			this.tabControl1.Location = new System.Drawing.Point(0, 0);
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(768, 672);
			this.tabControl1.TabIndex = 1;
			// 
			// tabPage1
			// 
			this.tabPage1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("tabPage1.BackgroundImage")));
			this.tabPage1.Controls.Add(this.groupBoxClassify);
			this.tabPage1.Controls.Add(this.groupBoxNote);
			this.tabPage1.Controls.Add(this.groupBoxImage);
			this.tabPage1.Controls.Add(this.groupBoxSound);
			this.tabPage1.Controls.Add(this.label2);
			this.tabPage1.Controls.Add(this.label1);
			this.tabPage1.Controls.Add(this.txtTitle);
			this.tabPage1.Controls.Add(this.txtSectionTitle);
			this.tabPage1.Location = new System.Drawing.Point(4, 25);
			this.tabPage1.Name = "tabPage1";
			this.tabPage1.Size = new System.Drawing.Size(760, 643);
			this.tabPage1.TabIndex = 0;
			this.tabPage1.Text = "Topic Info";
			// 
			// groupBoxClassify
			// 
			this.groupBoxClassify.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.groupBoxClassify.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxClassify.BackgroundImage")));
			this.groupBoxClassify.Controls.Add(this.txtDiffLevel);
			this.groupBoxClassify.Controls.Add(this.label7);
			this.groupBoxClassify.Controls.Add(this.cmbBook);
			this.groupBoxClassify.Controls.Add(this.label4);
			this.groupBoxClassify.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxClassify.Location = new System.Drawing.Point(8, 541);
			this.groupBoxClassify.Name = "groupBoxClassify";
			this.groupBoxClassify.Size = new System.Drawing.Size(248, 96);
			this.groupBoxClassify.TabIndex = 51;
			this.groupBoxClassify.TabStop = false;
			this.groupBoxClassify.Text = "Classify Infomation";
			// 
			// txtDiffLevel
			// 
			this.txtDiffLevel.Location = new System.Drawing.Point(88, 24);
			this.txtDiffLevel.Name = "txtDiffLevel";
			this.txtDiffLevel.Size = new System.Drawing.Size(144, 23);
			this.txtDiffLevel.TabIndex = 50;
			this.txtDiffLevel.Text = "";
			// 
			// label7
			// 
			this.label7.BackColor = System.Drawing.Color.Transparent;
			this.label7.Location = new System.Drawing.Point(8, 24);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(80, 16);
			this.label7.TabIndex = 49;
			this.label7.Text = "Difficult &Level";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// cmbBook
			// 
			this.cmbBook.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cmbBook.Location = new System.Drawing.Point(88, 56);
			this.cmbBook.Name = "cmbBook";
			this.cmbBook.Size = new System.Drawing.Size(144, 24);
			this.cmbBook.TabIndex = 48;
			// 
			// label4
			// 
			this.label4.BackColor = System.Drawing.Color.Transparent;
			this.label4.Location = new System.Drawing.Point(8, 56);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(80, 16);
			this.label4.TabIndex = 47;
			this.label4.Text = "&Book Name:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// groupBoxNote
			// 
			this.groupBoxNote.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBoxNote.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxNote.BackgroundImage")));
			this.groupBoxNote.Controls.Add(this.txtNote);
			this.groupBoxNote.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxNote.Location = new System.Drawing.Point(272, 541);
			this.groupBoxNote.Name = "groupBoxNote";
			this.groupBoxNote.Size = new System.Drawing.Size(480, 96);
			this.groupBoxNote.TabIndex = 50;
			this.groupBoxNote.TabStop = false;
			this.groupBoxNote.Text = "Notes";
			// 
			// txtNote
			// 
			this.txtNote.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtNote.Location = new System.Drawing.Point(8, 22);
			this.txtNote.Multiline = true;
			this.txtNote.Name = "txtNote";
			this.txtNote.Size = new System.Drawing.Size(464, 66);
			this.txtNote.TabIndex = 26;
			this.txtNote.Text = "";
			// 
			// groupBoxImage
			// 
			this.groupBoxImage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBoxImage.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxImage.BackgroundImage")));
			this.groupBoxImage.Controls.Add(this.txtPassages);
			this.groupBoxImage.Controls.Add(this.txtImage);
			this.groupBoxImage.Controls.Add(this.btnImage);
			this.groupBoxImage.Controls.Add(this.pBoxImage);
			this.groupBoxImage.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxImage.Location = new System.Drawing.Point(8, 272);
			this.groupBoxImage.Name = "groupBoxImage";
			this.groupBoxImage.Size = new System.Drawing.Size(744, 253);
			this.groupBoxImage.TabIndex = 49;
			this.groupBoxImage.TabStop = false;
			this.groupBoxImage.Text = "&Image && Text";
			// 
			// txtPassages
			// 
			this.txtPassages.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtPassages.Location = new System.Drawing.Point(8, 22);
			this.txtPassages.Multiline = true;
			this.txtPassages.Name = "txtPassages";
			this.txtPassages.Size = new System.Drawing.Size(344, 223);
			this.txtPassages.TabIndex = 48;
			this.txtPassages.Text = "";
			// 
			// txtImage
			// 
			this.txtImage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.txtImage.Location = new System.Drawing.Point(360, 221);
			this.txtImage.Name = "txtImage";
			this.txtImage.Size = new System.Drawing.Size(336, 23);
			this.txtImage.TabIndex = 47;
			this.txtImage.Text = "";
			// 
			// btnImage
			// 
			this.btnImage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btnImage.BackColor = System.Drawing.Color.Transparent;
			this.btnImage.Location = new System.Drawing.Point(704, 221);
			this.btnImage.Name = "btnImage";
			this.btnImage.Size = new System.Drawing.Size(32, 24);
			this.btnImage.TabIndex = 46;
			this.btnImage.Text = "...";
			this.btnImage.Click += new System.EventHandler(this.btnImage_Click);
			// 
			// pBoxImage
			// 
			this.pBoxImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.pBoxImage.BackColor = System.Drawing.Color.Transparent;
			this.pBoxImage.Image = ((System.Drawing.Image)(resources.GetObject("pBoxImage.Image")));
			this.pBoxImage.Location = new System.Drawing.Point(368, 22);
			this.pBoxImage.Name = "pBoxImage";
			this.pBoxImage.Size = new System.Drawing.Size(368, 191);
			this.pBoxImage.TabIndex = 45;
			this.pBoxImage.TabStop = false;
			this.pBoxImage.DoubleClick += new System.EventHandler(this.pBoxImage_DoubleClick);
			// 
			// groupBoxSound
			// 
			this.groupBoxSound.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBoxSound.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxSound.BackgroundImage")));
			this.groupBoxSound.Controls.Add(this.txtSound);
			this.groupBoxSound.Controls.Add(this.btnSound);
			this.groupBoxSound.Controls.Add(this.btnPlay);
			this.groupBoxSound.Controls.Add(this.txtTape);
			this.groupBoxSound.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxSound.Location = new System.Drawing.Point(8, 64);
			this.groupBoxSound.Name = "groupBoxSound";
			this.groupBoxSound.Size = new System.Drawing.Size(744, 189);
			this.groupBoxSound.TabIndex = 48;
			this.groupBoxSound.TabStop = false;
			this.groupBoxSound.Text = "&Sound && Tape Script:";
			// 
			// txtSound
			// 
			this.txtSound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.txtSound.Location = new System.Drawing.Point(576, 149);
			this.txtSound.Name = "txtSound";
			this.txtSound.Size = new System.Drawing.Size(128, 23);
			this.txtSound.TabIndex = 46;
			this.txtSound.Text = "";
			// 
			// btnSound
			// 
			this.btnSound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btnSound.BackColor = System.Drawing.Color.Transparent;
			this.btnSound.Location = new System.Drawing.Point(712, 149);
			this.btnSound.Name = "btnSound";
			this.btnSound.Size = new System.Drawing.Size(24, 24);
			this.btnSound.TabIndex = 45;
			this.btnSound.Text = "...";
			this.btnSound.Click += new System.EventHandler(this.btnSound_Click);
			// 
			// btnPlay
			// 
			this.btnPlay.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.btnPlay.BackColor = System.Drawing.Color.Transparent;
			this.btnPlay.Image = ((System.Drawing.Image)(resources.GetObject("btnPlay.Image")));
			this.btnPlay.Location = new System.Drawing.Point(576, 22);
			this.btnPlay.Name = "btnPlay";
			this.btnPlay.Size = new System.Drawing.Size(160, 111);
			this.btnPlay.TabIndex = 44;
			this.btnPlay.Text = ">>";
			this.btnPlay.Click += new System.EventHandler(this.btnPlay_Click);
			// 
			// txtTape
			// 
			this.txtTape.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtTape.Location = new System.Drawing.Point(8, 22);
			this.txtTape.Multiline = true;
			this.txtTape.Name = "txtTape";
			this.txtTape.Size = new System.Drawing.Size(552, 151);
			this.txtTape.TabIndex = 23;
			this.txtTape.Text = "";
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.Color.Transparent;
			this.label2.ForeColor = System.Drawing.Color.MediumBlue;
			this.label2.Location = new System.Drawing.Point(8, 8);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 16);
			this.label2.TabIndex = 42;
			this.label2.Text = "Section :";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.ForeColor = System.Drawing.Color.MediumBlue;
			this.label1.Location = new System.Drawing.Point(8, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 41;
			this.label1.Text = "Topic Title :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtTitle
			// 
			this.txtTitle.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtTitle.ForeColor = System.Drawing.Color.MediumBlue;
			this.txtTitle.Location = new System.Drawing.Point(88, 32);
			this.txtTitle.Name = "txtTitle";
			this.txtTitle.Size = new System.Drawing.Size(664, 23);
			this.txtTitle.TabIndex = 40;
			this.txtTitle.Text = "";
			// 
			// txtSectionTitle
			// 
			this.txtSectionTitle.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtSectionTitle.ForeColor = System.Drawing.Color.Crimson;
			this.txtSectionTitle.Location = new System.Drawing.Point(88, 8);
			this.txtSectionTitle.Name = "txtSectionTitle";
			this.txtSectionTitle.ReadOnly = true;
			this.txtSectionTitle.Size = new System.Drawing.Size(664, 23);
			this.txtSectionTitle.TabIndex = 24;
			this.txtSectionTitle.Text = "";
			// 
			// buttonOk
			// 
			this.buttonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.buttonOk.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.buttonOk.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonOk.BackgroundImage")));
			this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.buttonOk.Location = new System.Drawing.Point(432, 680);
			this.buttonOk.Name = "buttonOk";
			this.buttonOk.Size = new System.Drawing.Size(96, 32);
			this.buttonOk.TabIndex = 2;
			this.buttonOk.Text = "&Save";
			this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
			// 
			// buttonCancel
			// 
			this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.buttonCancel.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.buttonCancel.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonCancel.BackgroundImage")));
			this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.buttonCancel.Location = new System.Drawing.Point(544, 680);
			this.buttonCancel.Name = "buttonCancel";
			this.buttonCancel.Size = new System.Drawing.Size(96, 32);
			this.buttonCancel.TabIndex = 3;
			this.buttonCancel.Text = "&Cancel";
			this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
			// 
			// buttonHelp
			// 
			this.buttonHelp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.buttonHelp.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.buttonHelp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonHelp.BackgroundImage")));
			this.buttonHelp.Enabled = false;
			this.buttonHelp.Location = new System.Drawing.Point(656, 680);
			this.buttonHelp.Name = "buttonHelp";
			this.buttonHelp.Size = new System.Drawing.Size(96, 32);
			this.buttonHelp.TabIndex = 4;
			this.buttonHelp.Text = "&Help";
			this.buttonHelp.Click += new System.EventHandler(this.buttonHelp_Click);
			// 
			// FormTopic
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 16);
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(768, 718);
			this.Controls.Add(this.buttonHelp);
			this.Controls.Add(this.buttonCancel);
			this.Controls.Add(this.buttonOk);
			this.Controls.Add(this.tabControl1);
			this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MinimizeBox = false;
			this.Name = "FormTopic";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Topic Information";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.FormTopic_Closing);
			this.Load += new System.EventHandler(this.FormTopic_Load);
			this.tabControl1.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			this.groupBoxClassify.ResumeLayout(false);
			this.groupBoxNote.ResumeLayout(false);
			this.groupBoxImage.ResumeLayout(false);
			this.groupBoxSound.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void buttonOk_Click(object sender, System.EventArgs e)
		{
			CleanUp();
			int TopID = (int)TopicID;
			if(TopID == 0)
				MyDatabase.GenerateTopicID(ref TopID);
			string stTopic = TopID.ToString();
			if(stTopic.Length < 5)
				stTopic = stTopic.PadLeft(5,'0');
			if(txtSound.Text.Length > 0 && txtSound.Text.IndexOf(":") != -1)
			{
				//copy
				string stExtension = txtSound.Text.Substring(txtSound.Text.Length - 4);
				string stFile = SectionID.ToString() + "T" + stTopic + stExtension;
				File.Copy(txtSound.Text, Environment.CurrentDirectory + "\\Sounds\\" + stFile, true);
				txtSound.Text = stFile;
			}

			if(txtImage.Text.Length > 0 && txtImage.Text.IndexOf(":") != -1)
			{
				//copy
				string stExtension = txtImage.Text.Substring(txtImage.Text.Length - 4);
				string stFile = SectionID.ToString() + "T" + stTopic + stExtension;
				File.Copy(txtImage.Text, Environment.CurrentDirectory + "\\Images\\" + stFile, true);
				txtImage.Text = stFile;
			}

			
			if(TopicID == 0)
			{
				if(!DB2MainForm.AddTopic(SectionID,TopicID,txtTitle,txtPassages,txtTape,txtImage,txtSound,txtNote,txtDiffLevel,cmbBook))
				{
					MessageBox.Show("Cannot add topic","Add Topic - Error");
				}
			}
			else
			{
				if(!DB2MainForm.UpdateTopic(SectionID,TopicID,txtTitle,txtPassages,txtTape,txtImage,txtSound,txtNote,txtDiffLevel,cmbBook))
				{
					MessageBox.Show("Cannot update data.","Update Topic - Error");
				}
			}
			this.Close();
		}

		private void buttonCancel_Click(object sender, System.EventArgs e)
		{
			CleanUp();
			this.Close();
			
		}

		private void buttonHelp_Click(object sender, System.EventArgs e)
		{
		
		}

		private void FormTopic_Load(object sender, System.EventArgs e)
		{
			switch (SectionID)
			{
				case 1:
				case 2:
				case 3:
				case 5:
				case 6:
					this.Size = new Size(this.Size.Width, 275);
					groupBoxSound.Visible = groupBoxImage.Visible = false;
					groupBoxNote.Location = new System.Drawing.Point(groupBoxNote.Location.X, groupBoxSound.Location.Y);
					groupBoxClassify.Location = new System.Drawing.Point(groupBoxClassify.Location.X, groupBoxSound.Location.Y);
					break;
				case 4:
					Size z1 = new Size(groupBoxSound.Size.Width, groupBoxSound.Size.Height);
					this.Size = new Size(this.Size.Width, 490);
					groupBoxSound.Size = z1;

					groupBoxSound.Visible = true;
					groupBoxImage.Visible = false;
					groupBoxNote.Location = new System.Drawing.Point(groupBoxNote.Location.X, groupBoxSound.Location.Y + groupBoxSound.Size.Height + 10);
					groupBoxClassify.Location = new System.Drawing.Point(groupBoxClassify.Location.X, groupBoxSound.Location.Y + groupBoxSound.Size.Height + 10);
					break;
				case 7:
					z1 = new Size(groupBoxImage.Size.Width, groupBoxImage.Size.Height);
					this.Size = new Size(this.Size.Width, 560);
					groupBoxImage.Size = z1;
					
					groupBoxImage.Visible = true;
					groupBoxSound.Visible = false;
					groupBoxImage.Location = new System.Drawing.Point(groupBoxImage.Location.X, groupBoxSound.Location.Y);
					groupBoxNote.Location = new System.Drawing.Point(groupBoxNote.Location.X, groupBoxImage.Location.Y + groupBoxImage.Size.Height + 10);
					groupBoxClassify.Location = new System.Drawing.Point(groupBoxClassify.Location.X, groupBoxImage.Location.Y + groupBoxImage.Size.Height + 10);
					break;
			}

			if(TopicID > 0)
			{
				DB2MainForm.LoadTopic(SectionID,TopicID,ref txtTitle,ref txtPassages,ref  txtTape, ref txtImage, ref txtSound, ref txtNote, ref txtDiffLevel, ref cmbBook);
				if(txtImage.Text != "")
				{
					pBoxImage.Image = Image.FromFile(Environment.CurrentDirectory + "\\Images\\" + txtImage.Text);
				}
			}
			else
				DB2MainForm.LoadBooks(ref cmbBook);
			
		}

		private void pBoxImage_DoubleClick(object sender, System.EventArgs e)
		{
		
		}

		private void btnPlay_Click(object sender, System.EventArgs e)
		{
			string stFile = txtSound.Text;
			try
			{
				if(m_objMediaControl != null)
				{
					CleanUp();
				}
				else
				{
					
					if(stFile.IndexOf(":") == -1)
						stFile = Environment.CurrentDirectory + "\\Sounds\\" + txtSound.Text;
					m_objFilterGraph = new FilgraphManager();
					m_objFilterGraph.RenderFile(stFile);

					m_objBasicAudio = m_objFilterGraph as IBasicAudio;
                
					m_objMediaEvent = m_objFilterGraph as IMediaEvent;

					m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
					m_objMediaEventEx.SetNotifyWindow((int) this.Handle,WM_GRAPHNOTIFY, 0);

					m_objMediaPosition = m_objFilterGraph as IMediaPosition;

					m_objMediaControl = m_objFilterGraph as IMediaControl;

					m_objMediaControl.Run();
				}
			}catch(Exception)
			{

			}
		}

		private void btnSound_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog dlg = new OpenFileDialog();
			dlg.Filter = "Wave files (*.wav)|*.wav|MP3 files(*.mp3)|*.mp3|All files (*.*)|*.*";
			dlg.RestoreDirectory = true;

			if (dlg.ShowDialog() == DialogResult.OK)
			{
				txtSound.Text = dlg.FileName;
			}
		}

		private void btnImage_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog dlg = new OpenFileDialog();
			dlg.Filter = "JPEG files (*.jpg)|*.jpg|GIF files(*.gif)|*.gif|Bitmap files(*.bmp)|*.bmp|All files (*.*)|*.*";
			dlg.RestoreDirectory = true;

			if (dlg.ShowDialog() == DialogResult.OK)
			{
				txtImage.Text = dlg.FileName;
				pBoxImage.Image = Image.FromFile(dlg.FileName);
			}
		}
		private void CleanUp()
		{
			if (m_objMediaControl != null)
				m_objMediaControl.Stop();

			

			if (m_objMediaEventEx != null)
				m_objMediaEventEx.SetNotifyWindow(0, 0, 0);

			if (m_objVideoWindow != null)
			{
				m_objVideoWindow.Visible = 0;
				m_objVideoWindow.Owner = 0;
			}

			if (m_objMediaControl != null) m_objMediaControl = null;
			if (m_objMediaPosition != null) m_objMediaPosition = null;
			if (m_objMediaEventEx != null) m_objMediaEventEx = null;
			if (m_objMediaEvent != null) m_objMediaEvent = null;
			if (m_objVideoWindow != null) m_objVideoWindow = null;
			if (m_objBasicAudio != null) m_objBasicAudio = null;
			if (m_objFilterGraph != null) m_objFilterGraph = null;
		}
		protected override void WndProc( ref Message m)
		{
			if (m.Msg == WM_GRAPHNOTIFY)
			{
				int lEventCode;
				int lParam1, lParam2;

				while (true)
				{
					try
					{
						m_objMediaEventEx.GetEvent(out lEventCode, 
							out lParam1,
							out lParam2,
							0); 
 
						m_objMediaEventEx.FreeEventParams(lEventCode, lParam1, lParam2);

						if (lEventCode == EC_COMPLETE)
						{
							CleanUp();
							
						}
					} 
					catch (Exception)
					{
						break;
					}
				}
			}

			base.WndProc(ref m);
		}

		private void FormTopic_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			CleanUp();
		}
	}
}
